Trò chơi Angry Birds trong UNITY Engine
31.683 lượt xem;
1 using UnityEngine;
2 using System;
3 using System.Collections;
4
5
6 public abstract class AbstractTweenProperty
7 {
8 protected bool _isInitialized;
9 public bool isInitialized { get { return _isInitialized; } }
10
11 protected bool _isRelative;
12 protected GoTween _ownerTween;
13
14 protected Func<float, float, float, float, float> _easeFunction;
15
16
17
18 public AbstractTweenProperty( bool isRelative = false )
19 {
20 _isRelative = isRelative;
21 }
22
23
24 public override int GetHashCode()
25 {
26 return base.GetHashCode();
27 }
28
29
30 /// <summary>
31 /// checks to see if a TweenProperty matches another. checks propertyNames of IGenericPropertys first then
32 /// resorts to direct type checking
33 /// </summary>
34 public override bool Equals( object obj )
35 {
36 // null check first
37 if( obj == null )
38 return false;
39
40 // handle IGenericProperty comparisons which just have the property name checked
41 if( this is IGenericProperty && obj is IGenericProperty )
42 return ((IGenericProperty)this).propertyName == ((IGenericProperty)obj).propertyName;
43
44 // check for the same types
45 if( obj.GetType() == this.GetType() )
46 return true;
47
48 return base.Equals( obj );
49 }
50
51
52 /// <summary>
53 /// called by a Tween just after this property is validated and added to the Tweens property list
54 /// </summary>
55 public virtual void init( GoTween owner )
56 {
57 _isInitialized = true;
58 _ownerTween = owner;
59
60 // if we dont have an easeFunction use the owners type
61 if( _easeFunction == null )
62 setEaseType( owner.easeType );
63 }
64
65
66 /// <summary>
67 /// clones the instance
68 /// </summary>
69 public AbstractTweenProperty clone()
70 {
71 var clone = MemberwiseClone() as AbstractTweenProperty;
72 clone._ownerTween = null;
73 clone._isInitialized = false;
74 clone._easeFunction = null;
75
76 return clone;
77 }
78
79
80 /// <summary>
81 /// sets the ease type for this tween property
82 /// technically, this should be an internal method
83 /// </summary>
84 public void setEaseType( GoEaseType easeType )
85 {
86 _easeFunction = GoTweenUtils.easeFunctionForType( easeType );
87 }
88
89
90 /// <summary>
91 /// each TweenProperty should override this to ensure the object is the correct type
92 /// </summary>
93 public virtual bool validateTarget( object target )
94 {
95 return true;
96 }
97
98
99 /// <summary>
100 /// subclasses should get the eased time then set the new value on the object
101 /// </summary>
102 public abstract void tick( float totalElapsedTime );
103
104
105 /// <summary>
106 /// called when a Tween is initially started.
107 /// subclasses should strongly type the start/end/target and handle isFrom with
108 /// regard to setting the proper start/end values
109 /// </summary>
110 public abstract void prepareForUse();
111
112 }
2 using System;
3 using System.Collections;
4
5
6 public abstract class AbstractTweenProperty
7 {
8 protected bool _isInitialized;
9 public bool isInitialized { get { return _isInitialized; } }
10
11 protected bool _isRelative;
12 protected GoTween _ownerTween;
13
14 protected Func<float, float, float, float, float> _easeFunction;
15
16
17
18 public AbstractTweenProperty( bool isRelative = false )
19 {
20 _isRelative = isRelative;
21 }
22
23
24 public override int GetHashCode()
25 {
26 return base.GetHashCode();
27 }
28
29
30 /// <summary>
31 /// checks to see if a TweenProperty matches another. checks propertyNames of IGenericPropertys first then
32 /// resorts to direct type checking
33 /// </summary>
34 public override bool Equals( object obj )
35 {
36 // null check first
37 if( obj == null )
38 return false;
39
40 // handle IGenericProperty comparisons which just have the property name checked
41 if( this is IGenericProperty && obj is IGenericProperty )
42 return ((IGenericProperty)this).propertyName == ((IGenericProperty)obj).propertyName;
43
44 // check for the same types
45 if( obj.GetType() == this.GetType() )
46 return true;
47
48 return base.Equals( obj );
49 }
50
51
52 /// <summary>
53 /// called by a Tween just after this property is validated and added to the Tweens property list
54 /// </summary>
55 public virtual void init( GoTween owner )
56 {
57 _isInitialized = true;
58 _ownerTween = owner;
59
60 // if we dont have an easeFunction use the owners type
61 if( _easeFunction == null )
62 setEaseType( owner.easeType );
63 }
64
65
66 /// <summary>
67 /// clones the instance
68 /// </summary>
69 public AbstractTweenProperty clone()
70 {
71 var clone = MemberwiseClone() as AbstractTweenProperty;
72 clone._ownerTween = null;
73 clone._isInitialized = false;
74 clone._easeFunction = null;
75
76 return clone;
77 }
78
79
80 /// <summary>
81 /// sets the ease type for this tween property
82 /// technically, this should be an internal method
83 /// </summary>
84 public void setEaseType( GoEaseType easeType )
85 {
86 _easeFunction = GoTweenUtils.easeFunctionForType( easeType );
87 }
88
89
90 /// <summary>
91 /// each TweenProperty should override this to ensure the object is the correct type
92 /// </summary>
93 public virtual bool validateTarget( object target )
94 {
95 return true;
96 }
97
98
99 /// <summary>
100 /// subclasses should get the eased time then set the new value on the object
101 /// </summary>
102 public abstract void tick( float totalElapsedTime );
103
104
105 /// <summary>
106 /// called when a Tween is initially started.
107 /// subclasses should strongly type the start/end/target and handle isFrom with
108 /// regard to setting the proper start/end values
109 /// </summary>
110 public abstract void prepareForUse();
111
112 }